package com.llyb.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.llyb.tingshu.album.service.BaseCategoryService;
import com.llyb.tingshu.common.result.Result;
import com.llyb.tingshu.model.album.BaseAttribute;
import com.llyb.tingshu.model.album.BaseCategory1;
import com.llyb.tingshu.model.album.BaseCategory3;
import com.llyb.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;


	@Operation(summary = "查询所有列表")
	@GetMapping("getBaseCategoryList")
	public Result getBaseCategoryList(){

		List<JSONObject> categoryList = baseCategoryService.getBaseCategoryList();

		return Result.ok(categoryList);
	}

	@Operation(summary = "查询属性和属性值")
	@GetMapping("/findAttribute/{category1Id}")
	public Result getAttribute(@PathVariable("category1Id") String category1Id){

		List<BaseAttribute> albumAttributeValueVoList = baseCategoryService.getAttribute(category1Id);

		return Result.ok(albumAttributeValueVoList);

	}


	/**
	 * 根据三级分类id获取所有分类id
	 * @param category3Id
	 * @return
	 */
	@Operation(summary = "根据三级分类id获取所有分类id")
	@GetMapping("/getCategoryView/{category3Id}")
	public Result getCategoryView(@PathVariable("category3Id") Long category3Id){
		BaseCategoryView baseCategoryView = baseCategoryService.getCategoryView(category3Id);
		return Result.ok(baseCategoryView);
	}

	@Operation(summary = "根据一级分类id获取所有的分类信息")
	@GetMapping("/getBaseCategoryList/{category1id}")
	public Result getBaseCategoryList(@PathVariable("category1id") Long category1id){

		JSONObject jsonObject1 = baseCategoryService.getBaseCategoryList(category1id);

		return Result.ok(jsonObject1);
	}

	/**
	 * 根据一级分类id查询所有3级分类id
	 * @param category1Id
	 * @return
	 */
	@Operation(summary = "根据一级分类id查询所有3级分类id")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result findTopBaseCategory3(@PathVariable("category1Id") Long category1Id){

		List<BaseCategory3> baseCategory3List = baseCategoryService.findTopBaseCategory3(category1Id);

		return Result.ok(baseCategory3List);
	}


	@GetMapping("/findAllCategory1")
	Result<List<BaseCategory1>> findAllCategory1(){
		//	获取所有的一级分类数据
		List<BaseCategory1> baseCategory1List = baseCategoryService.findAllCategory1();
		return Result.ok(baseCategory1List);
	}

}

